package paint;

import java.awt.*;
import java.awt.Toolkit.*;

/** saveChanges provides the user to choose to save or not all changes made on main canvas.
 * There are no OS/Hardware dependencies and no variances.  There is no need for any
 * security constraints and no references to external specifications.
 */
public class saveChanges extends javax.swing.JDialog {

    /** Creates new form saveChanges. */
    String fileName;
    /** Integer to signify 'YES', 'NO', and 'CANCEL'.
     */
    public int CHOICE;

    /** Constructor initializes the dialog box to proper size.
     * There are no OS/Hardware dependencies and no variances.  There is no need for any
     * security constraints and no references to external specifications.
     * @param parent Frame containing image frame
     * @param modal boolean indicating true or false
     * @param filename String containing the file nameS
     */
    public saveChanges(java.awt.Frame parent, boolean modal, String filename) {
        super(parent, modal);
        fileName = filename;
        initComponents();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        double xMargin = (screenSize.getWidth() - this.getWidth()) / 2;
        double yMargin = (screenSize.getHeight() - this.getHeight()) / 2;
        this.setLocation((int) xMargin, (int) yMargin);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     * There are no OS/Hardware dependencies and no variances.	There is no need for any
     * security constraints and no references to external specifications.
     */
    public void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        YES = new javax.swing.JButton();
        NO = new javax.swing.JButton();
        CANCEL = new javax.swing.JButton();
        Alert = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints1;

        addWindowListener(new java.awt.event.WindowAdapter() {

            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jLabel1.setText("Save changes to " + fileName + "?");
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 2;
        gridBagConstraints1.gridy = 0;
        gridBagConstraints1.gridwidth = 3;
        getContentPane().add(jLabel1, gridBagConstraints1);

        YES.setText("YES");
        YES.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                YESActionPerformed(evt);
            }
        });

        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 1;
        gridBagConstraints1.gridy = 1;
        getContentPane().add(YES, gridBagConstraints1);

        NO.setText("NO");
        NO.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NOActionPerformed(evt);
            }
        });

        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 2;
        gridBagConstraints1.gridy = 1;
        getContentPane().add(NO, gridBagConstraints1);

        CANCEL.setText("CANCEL");
        CANCEL.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CANCELActionPerformed(evt);
            }
        });

        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 3;
        gridBagConstraints1.gridy = 1;
        getContentPane().add(CANCEL, gridBagConstraints1);

        Alert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exclamation.gif")));
        Alert.setBorder(null);
        Alert.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AlertActionPerformed(evt);
            }
        });

        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 0;
        getContentPane().add(Alert, gridBagConstraints1);

        pack();
    }

    /** This method is performed when a user clicks YES button to save the changes.
     * There are no OS/Hardware dependencies and no variances.	There is no need for any
     * security constraints and no references to external specifications.
     *@param evt performed by mouse action.
     */
    public void YESActionPerformed(java.awt.event.ActionEvent evt) {
        CHOICE = choice.YES;
        this.closeDialog(new java.awt.event.WindowEvent(this, 0));
    // Add your handling code here:
    }

    /** This method is performed by mouse event when user clicks CANCEL button to cancel the changes.
     * There are no OS/Hardware dependencies and no variances.	There is no need for any
     * security constraints and no references to external specifications.
     *@param evt performed by mouse event.
     */
    public void CANCELActionPerformed(java.awt.event.ActionEvent evt) {
        CHOICE = choice.CANCEL;
        this.closeDialog(new java.awt.event.WindowEvent(this, 0));
    // Add your handling code here:
    }

    /** This method is performed by mouse event when user clicks NO button not to save the changes.
     * There are no OS/Hardware dependencies and no variances.	There is no need for any
     * security constraints and no references to external specifications.
     *@param evt performed by mouse action.
     */
    public void NOActionPerformed(java.awt.event.ActionEvent evt) {
        CHOICE = choice.NO;
        this.closeDialog(new java.awt.event.WindowEvent(this, 0));
    // Add your handling code here:
    }

    /** This method is executed by mouse event when user clicks Alert button.
     * There are no OS/Hardware dependencies and no variances.	There is no need for any
     * security constraints and no references to external specifications.
     *@param evt performed by mouse event.
     */
    public void AlertActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
    }

    /** Closes the dialog.
     * There are no OS/Hardware dependencies and no variances.	There is no need for any
     * security constraints and no references to external specifications.
     *@param evt performed by mouse event.
     */
    private void closeDialog(java.awt.event.WindowEvent evt) {
        setVisible(false);
        dispose();
    }

    /** Creates new saveChanges object.
     * There are no OS/Hardware dependencies and no variances.	There is no need for any
     * security constraints and no references to external specifications.
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new saveChanges(new javax.swing.JFrame(), true, "HELLO").show();
    }
    // Variables declaration - do not modify
    /** java swing GUI depicting the JLabel called jLabell.*/
    public javax.swing.JLabel jLabel1;
    /** java swing GUI depicting the Jbutton called YES.*/
    public javax.swing.JButton YES;
    /** java swing GUI depicting the Jbutton called NO.*/
    public javax.swing.JButton NO;
    /** java swing GUI depicting the Jbutton called CANCEL.*/
    public javax.swing.JButton CANCEL;
    /** java swing GUI depicting the Jbutton called Alert.*/
    public javax.swing.JButton Alert;

    // End of variables declaration
}

/** Subclass choice providing YES, NO, or CANCEL when made changes. */
class choice {

    /** YES set to 0. */
    public static int YES = 0;
    /** NO set to 1. */
    public static int NO = 1;
    /** CANCEL set to 2. */
    public static int CANCEL = 2;
}
